import moment from 'moment';
import { expect } from 'chai';
import { generateCuttoffs } from './index';

const to = moment().set({
    year: 2020, month: 8, date: 2, hour: 0, minute: 0, second: 0,
}).add(10, 'days').valueOf() / 1000;

const from = moment().set({
    year: 2020, month: 8, date: 2, hour: 0, minute: 0, second: 0,
}).subtract(20, 'weeks').valueOf() / 1000;

const nBuckets = 21;

const results = [
    ['12:00:00 15 - 04 - 2020', '11:59:59 21 - 04 - 2020'],
    ['12:00:00 22 - 04 - 2020', '11:59:59 28 - 04 - 2020'],
    ['12:00:00 29 - 04 - 2020', '11:59:59 05 - 05 - 2020'],
    ['12:00:00 06 - 05 - 2020', '11:59:59 12 - 05 - 2020'],
    ['12:00:00 13 - 05 - 2020', '11:59:59 19 - 05 - 2020'],
    ['12:00:00 20 - 05 - 2020', '11:59:59 26 - 05 - 2020'],
    ['12:00:00 27 - 05 - 2020', '11:59:59 02 - 06 - 2020'],
    ['12:00:00 03 - 06 - 2020', '11:59:59 09 - 06 - 2020'],
    ['12:00:00 10 - 06 - 2020', '11:59:59 16 - 06 - 2020'],
    ['12:00:00 17 - 06 - 2020', '11:59:59 23 - 06 - 2020'],
    ['12:00:00 24 - 06 - 2020', '11:59:59 30 - 06 - 2020'],
    ['12:00:00 01 - 07 - 2020', '11:59:59 07 - 07 - 2020'],
    ['12:00:00 08 - 07 - 2020', '11:59:59 14 - 07 - 2020'],
    ['12:00:00 15 - 07 - 2020', '11:59:59 21 - 07 - 2020'],
    ['12:00:00 22 - 07 - 2020', '11:59:59 28 - 07 - 2020'],
    ['12:00:00 29 - 07 - 2020', '11:59:59 04 - 08 - 2020'],
    ['12:00:00 05 - 08 - 2020', '11:59:59 11 - 08 - 2020'],
    ['12:00:00 12 - 08 - 2020', '11:59:59 18 - 08 - 2020'],
    ['12:00:00 19 - 08 - 2020', '11:59:59 25 - 08 - 2020'],
    ['12:00:00 26 - 08 - 2020', '11:59:59 01 - 09 - 2020'],
    ['12:00:00 02 - 09 - 2020', '11:59:59 08 - 09 - 2020'],
    ['12:00:00 09 - 09 - 2020', '12:00:00 12 - 09 - 2020'],
];


describe('test bucket fill functions', () => {
    it('buckets with a duration of 7 or more days should start and end at midnight', () => {
        const cutoffs = generateCuttoffs(from, to, nBuckets);
        cutoffs.forEach((cutoff, i) => {
            expect(moment(cutoff[0] * 1000).format('hh:mm:ss DD - MM - Y')).to.equal(results[i][0]);
            expect(moment(cutoff[1] * 1000).format('hh:mm:ss DD - MM - Y')).to.equal(results[i][1]);
        });
    });
});
